/**
 * Copyright (c) 2006-2016 Huize Ltd. All Rights Reserved. 
 *  
 * This code is the confidential and proprietary information of   
 * Hzins. You shall not disclose such Confidential Information   
 * and shall use it only in accordance with the terms of the agreements   
 * you entered into with Huize,http://www.huize.com.
 *  
 */
package com.agan.concurrent.lock;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author hz1412988
 * @date 2018年2月9日 下午5:38:09
 * @version
 */
public class TTTT {

    public static void main(String[] args) {

	Thread i1 = new Thread(new RunIt3());
	Thread i2 = new Thread(new RunIt3());
	i1.start();
	i2.start();
	i2.interrupt();
    }

}

class RunIt3 implements Runnable {

    private static Lock lock = new ReentrantLock();

    public void run() {
	try {
	    // ---------------------------------a
	    // lock.lock();
	    lock.lockInterruptibly();

	    System.out.println(Thread.currentThread().getName() + " running");
	    TimeUnit.SECONDS.sleep(10);
	    lock.unlock();
	    System.out.println(Thread.currentThread().getName() + " finished");
	} catch (InterruptedException e) {
	    System.out.println(Thread.currentThread().getName() + " interrupted");

	}

    }
}